using System.Collections.Generic;

namespace Aks.Deployment.SharePoint.Data
{
	#region | Extension |

	/// <summary>
	/// Extension methods for the <see cref="CamlComparisonType"/> class.
	/// </summary>
	internal static class CamlComparisonTypeExtension
	{
		private static readonly Dictionary<CamlComparisonType, string> _allValues = new Dictionary<CamlComparisonType, string>
    	{
			{ CamlComparisonType.EqualTo,            "Eq" },
			{ CamlComparisonType.NotEqualTo,         "Neq" },
			{ CamlComparisonType.LessThan,           "Lt" },
			{ CamlComparisonType.LessThanEqualTo,    "Leq" },
			{ CamlComparisonType.GreaterThan,        "Gt" },
			{ CamlComparisonType.GreaterThanEqualTo, "Geq" },
			{ CamlComparisonType.StartsWith,         "BeginsWith" },
			{ CamlComparisonType.Contains,		     "Contains" },
			{ CamlComparisonType.IsNull,             "IsNull" },
			{ CamlComparisonType.IsNotNull,          "IsNotNull" },
			{ CamlComparisonType.And,                "And" },
			{ CamlComparisonType.Or,                 "Or" }
		};


		/// <summary>
		/// Returns a string representation of the CAML comparison type.
		/// </summary>
		/// <param name="type">The type.</param>
		/// <returns>A string representation of the comparison type.</returns>
		public static string ToCaml(this CamlComparisonType type)
		{
			// assuming all values are represented in the dictionary, null should never be returned
			return (_allValues.ContainsKey(type)) ? _allValues[type] : null;
		}
	}
	
	#endregion


	/// <summary>
	/// Represents a type of <see cref="CamlComparison"/>.
	/// </summary>
	internal enum CamlComparisonType
	{
		/// <summary>Signifies an "equal to" comparison.</summary>
		EqualTo,

		/// <summary>Signifies a "not equal to" comparison.</summary>
		NotEqualTo,

		/// <summary>Signifies a "less than" comparison.</summary>
		LessThan,

		/// <summary>Signifies a "less than or equal to" comparison.</summary>
		LessThanEqualTo,

		/// <summary>Signifies a "greater than" comparison.</summary>
		GreaterThan,

		/// <summary>Signifies a "greater than or equal to" comparison.</summary>
		GreaterThanEqualTo,

		/// <summary>Signifies a "starts with" comparison.</summary>
		StartsWith,

		/// <summary>Signifies a "contains" comparison.</summary>
		Contains,

		/// <summary>Signifies a "null" comparison.</summary>
		IsNull,

		/// <summary>Signifies a "not null" comparison.</summary>
		IsNotNull,

		/// <summary>Signifies an "and" comparison of two other comparisons.</summary>
		And,

		/// <summary>Signifies an "or" comparison of two other comparisons.</summary>
		Or
	}
}
